package com.xbongbong.saas.model;


import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.saas.domain.entity.BusinessProductEntity;
import com.xbongbong.saas.domain.entity.ReturnedPurchaseProductEntity;

import java.util.List;
import java.util.Map;

/**
 * @author
 */
public interface ReturnedPurchaseProductModel extends IModel<ReturnedPurchaseProductEntity> {



    Integer insertBatch(List<ReturnedPurchaseProductEntity> productAddList);

    /**
     * 保存
     *
     * @param returnedPurchaseProductEntity 插入实体
     * @return java.lang.Integer
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    Integer save(ReturnedPurchaseProductEntity returnedPurchaseProductEntity);
    /**
     * 根据主键删除记录
     *
     * @param key    主键
     * @param corpid 公司id
     * @return java.lang.Integer
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    Integer deleteByKey(Long key, String corpid);
    /**
     * 删除采购退货单下的所有产品根据采购退货单Id
     *
     * @param returnPurchaseId    id集合
     * @param corpid 公司id
     * @return java.lang.Integer
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    Integer deleteByReturnPurchaseId(Long returnPurchaseId, String corpid);
    /**
     * 删除多条采购退货单下下的所有产品
     *
     * @param returnPurchaseIdIn    id集合
     * @param corpid 公司id
     * @return java.lang.Integer
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    Integer deleteByReturnPurchaseIdIn(List<Long> returnPurchaseIdIn, String corpid);
    /**
     * 获取一条采购退货单产品数据
     *
     * @param key 采购合同产品ID
     * @param corpid 公司id
     * @return ReturnedPurchaseProductEntity 一条数据实体
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    ReturnedPurchaseProductEntity getByKey(Long key, String corpid);
    /**
     * 多参数查询多条数据
     *
     * @param param 参数集合
     * @return List<ReturnedPurchaseProductEntity> 数据集合
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    @Override
    List<ReturnedPurchaseProductEntity> findEntitys(Map<String, Object> param);
    /**
     * 关联查询
     *
     * @param param 参数集合
     * @return  List<ReturnedPurchaseProductEntity> Id集合
     * @author Jian.Wang
     * @date 2019/2/21 15:18
     */
    List<ReturnedPurchaseProductEntity> findEntitysJoinProduct(Map<String, Object> param);
    /**
     * 获取采购退货单关联产品
     * @param corpid      公司id
     * @param returnedPurchaseId  采购退货单id
     * @return 采购退货单产品列表
     * @author lcx
     * @date 2019/2/27 20:26
     */
    List<ReturnedPurchaseProductEntity> getProductsByRetPurchaseId(String corpid, Long returnedPurchaseId);

    /**
     * 获取采购退货单关联产品
     * @param corpid      公司id
     * @param returnedPurchaseId  采购退货单id
     * @param delIn 
     * @return 采购退货单产品列表
     * @author 吴峰
     * @date 2021/9/16 15:49
     */
    List<ReturnedPurchaseProductEntity> getProductsByRetPurchaseId(String corpid, Long returnedPurchaseId, List<Integer> delIn);

    /**
     * 获取产品合同根据合同id
     * @param corpid 公司id
     * @param purchaseIdIn 采购合同id
     * @return 数据
     */
    List<ReturnedPurchaseProductEntity> getReturnedPurchaseProductByReturnedPurchaseIdIn(String corpid, List<Long> purchaseIdIn);

    /**
     * 获取采购退货产品数量
     * @param param
     * @return
     */
    List<BusinessProductEntity> findProductNum(Map<String,Object> param);

    Integer findProductNumCount(Map<String,Object> param);

    Integer updateBatch(List<ReturnedPurchaseProductEntity> updateList, String corpid) throws XbbException;

    Integer updateOutstockBatch(List<ReturnedPurchaseProductEntity> updateList, String corpid) throws XbbException;

    Long isProductSubAttrExist(String attr, String corpid, Integer isArray);

    /**
     * 子表单数字字段汇总
     * @param corpid 公司id
     * @param field 需要汇总的字段
     * @param refId 单据id
     * @param productIdIn 单据在该产品关联的产品id 如生产单有物料产品和成品产品 refId为生产单id productIdIn为物料产品的id
     * @return
     */
    Double summaryByAttr(String field,String corpid,  Long refId, List<Long> productIdIn);

    Double summaryByAttrFromOutSide(String field,String corpid,  Long refId, List<Long> productIdIn);

    Double calcuateByAttrFromOutSide(String field1, String field2, String corpid, Long refId, List<Long> productIdIn);

    Long countProductSub(String attr, String corpid, Integer isArray);

    List<ReturnedPurchaseProductEntity> getProductWithSubData(String attr, String corpid, Integer isArray, Long idGte, Integer limit);

    Integer deleteBatch(List<Long> deleteList, String corpid, Integer del);

    Integer updateMulti(List<ReturnedPurchaseProductEntity> list, String corpid);

    List<ReturnedPurchaseProductEntity> getReturnedPurchaseProductById(Map<Long, Long>outstockFlowAndRefurned, String corpid);

}
